import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/home',
      name: 'home',
      component: HomeView
    },
    {
      path: '/class',
      name: 'class',
      component: () => import("@/views/ClassView.vue")
    },
    {
      path: '/plant',
      name: 'plant',
      component: () => import('@/views/PlantGrassView.vue')
    },
    {
      path: '/videodetail/:id',
      name: 'videodetail',
      component: () => import('@/views/plant/PlantVideoDetail.vue')
    },
    {
      path: '/headlinedetail/:id',
      name: 'headlinedetail',
      component: () => import('@/views/plant/HeadlineDetailView.vue')
    },
    {
      path: '/shopcart',
      name: 'shopcart',
      component: () => import("@/views/ShopCartView.vue")
    },
    {
      path: '/pay',
      name: 'pay',
      component: () => import("@/views/PayView.vue")
    },
    {
      path: '/paydetail',
      name: 'paydetail',
      component: () => import("@/views/pay/PayDetailView.vue")
    },
    {
      path: '/address',
      name: 'address',
      component: () => import("@/views/address/AddressView.vue")
    },
    {
      path: '/mine',
      name: 'mine',
      component: () => import("@/views/MineView.vue"),
    },
    {
      path: '/mycollect',
      name: 'mycollect',
      component: () => import("@/views/mine/CollectDetailView.vue"),
    },
    {
      path: '/myhistory',
      name: 'myhistory',
      component: () => import("@/views/mine/HistoryDetailView.vue"),
    },
    {
      path: '/order',
      name: 'order',
      component: () => import("@/views/mine/OrderDetailView.vue"),
    },
    {
      path: '/login',
      name: 'login',
      component: () => import("@/views/LoginView.vue")
    },
    {
      path: '/logindetail',
      name: 'logindetail',
      component: () => import("@/views/login/LoginDetail.vue")
    },
    {
      path: "/detail/:id",
      name: "detail",
      component: () => import("@/views/DetailView.vue")
    },
    {
      path: "/search",
      name: "search",
      component: () => import("@/views/search/SearchView.vue")
    },
    {
      path: '/searchResult/:kw',
      name: 'searchResult',
      component: () => import('@/views/search/SearchResultView.vue')
    },
    {
      path: "/detail/:id",
      name: "detail",
      component: () => import("@/views/DetailView.vue")
    },
    {
      path: "/miaosha",
      name: "miaosha",
      component: () => import("@/views/MiaoShaView.vue")
    },
    {
      path: "/colazb",
      name: "colazb",
      component: () => import("@/views/cola/ColaZbView.vue")
    },
    {
      path: "/zbDetail/:id",
      name: "zbDetail",
      component: () => import("@/views/cola/ZbDetailView.vue")
    },
    {
      path: "/colahs",
      name: "colahs",
      component: () => import("@/views/cola/ColaHsView.vue")
    },
    {
      path: "/coladesc",
      name: "coladesc",
      component: () => import("@/views/cola/ColaDescView.vue")
    },
    {
      path: "/",
      name: "start",
      redirect: "/home"
    },
  ],
})

// router.beforeEach(async (to, from) => {
//   if (to.name != "login" && to.name != "logindetail") {
//     const token = localStorage.getItem("token");
//     if(!token){
//       return { name: 'login' }
//     }
//     // 将用户重定向到登录页面
//   }
// })

export default router
